package com.southwind.config;

import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * sentinel 白名单、黑名单配置类
 */
public class RequestOriginParserDefinition implements RequestOriginParser {
    @Override
    public String
    parseOrigin(HttpServletRequest httpServletRequest) {
        // 一旦配置，所有的请求都必须带上这个参数
        String name = httpServletRequest.getParameter("name");
        if (StringUtils.isEmpty(name)) {
            throw new
                    RuntimeException("name is null");
        }
        return name;
    }
}
